version 14.1
set more off

***************************************************************************************************
*THIS FILE PRODUCES TABLE A.III OF SLEMROD-REHMAN-WASEEM-2020, RESTAT
***************************************************************************************************/

/* PRELIMINARIES */

#d					;
matrix 			input table=(0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0);
#d					cr
use				"$project_data\ITRM_Dislo_Unique_SelfEmployed_Heterog.dta", clear
bys				regno:egen namefreq=min(name_count_v2)
keep				if year<2012
g					logtaxpaid=log(TaxPaid)
qui				sum namefreq,d
g					treat=namefreq<=40
keep				if year==2010 | year==2011

/* TAXABLE INCOME */

g					logz=log(taxableinc)
local				i=1
local				j=1
forvalues		y=2011(-1)2010 {
forvalues		t=1(-1)0 {
qui				sum logz if treat==`t' & year==`y',d
matrix			table[`i',`j']=r(p25)
matrix 			table[`i'+1,`j']=r(p50)
matrix 			table[`i'+2,`j']=r(mean)
matrix 			table[`i'+3,`j']=r(p75)
matrix 			table[`i'+4,`j']=r(p90)
local				j=`j'+1
}
}
local				i=`i'+5

/* TAX PAID ON TAXABLE INCOME */

g					logtz=log(r9201)
local				j=1
forvalues		y=2011(-1)2010 {
forvalues		t=1(-1)0 {
qui				sum logtz if treat==`t' & year==`y',d
matrix			table[`i',`j']=r(p25)
matrix 			table[`i'+1,`j']=r(p50)
matrix 			table[`i'+2,`j']=r(mean)
matrix 			table[`i'+3,`j']=r(p75)
matrix 			table[`i'+4,`j']=r(p90)
local				j=`j'+1
}
}
local				i=`i'+5

/* FINAL TAX */

g					logtf=log(r9202)
local				j=1
forvalues		y=2011(-1)2010 {
forvalues		t=1(-1)0 {
qui				sum logtf if treat==`t' & year==`y',d
matrix			table[`i',`j']=r(p25)
matrix 			table[`i'+1,`j']=r(p50)
matrix 			table[`i'+2,`j']=r(mean)
matrix 			table[`i'+3,`j']=r(p75)
matrix 			table[`i'+4,`j']=r(p90)
local				j=`j'+1
}
}
local				i=`i'+5

/* TOP CITY */

preserve
drop				if it_office_id==.
g					trait=(it_office_id==1 | it_office_id==6 | 					///
					it_office_id==10 | it_office_id==16 | it_office_id==66 			///
					| it_office_id==70 | it_office_id==74 | it_office_id==97 		///
					| it_office_id==9 | it_office_id==20)
local				j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			se=e(V)
matrix			table[`i',`j']=[trait]1
matrix			table[`i'+1,`j']=sqrt(se[2,2])
local				j=`j'+1
matrix			table[`i',`j']=[trait]0
matrix			table[`i'+1,`j']=sqrt(se[1,1])
local				j=`j'+1
}
local				i=`i'+2
restore

/* PERSONAL CITY!=BUSINESS CITY */

preserve
drop				if personal_city_id==. | business_city_id==.
g					trait=(personal_city_id!=business_city_id)		
local				j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			se=e(V)
matrix			table[`i',`j']=[trait]1
matrix			table[`i'+1,`j']=sqrt(se[2,2])
local				j=`j'+1
matrix			table[`i',`j']=[trait]0
matrix			table[`i'+1,`j']=sqrt(se[1,1])
local				j=`j'+1
}
local				i=`i'+2
restore

/* MORE THAN ONE BUSINESSES */

preserve
drop				if no_of_business==.
g					trait=(no_of_business>1)		
local				j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			se=e(V)
matrix			table[`i',`j']=[trait]1
matrix			table[`i'+1,`j']=sqrt(se[2,2])
local				j=`j'+1
matrix			table[`i',`j']=[trait]0
matrix			table[`i'+1,`j']=sqrt(se[1,1])
local				j=`j'+1
}
local				i=`i'+2
restore

/* GENDER */

preserve
drop				if gender==""
g					trait=(gender=="F" | gender=="f" | gender=="2")	
replace			trait=1-trait	
local				j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			se=e(V)
matrix			table[`i',`j']=[trait]1
matrix			table[`i'+1,`j']=sqrt(se[2,2])
local				j=`j'+1
matrix			table[`i',`j']=[trait]0
matrix			table[`i'+1,`j']=sqrt(se[1,1])
local				j=`j'+1
}
local				i=`i'+2
restore

/* FILING DATE */

preserve
drop				if return_filing_date==.
g 					double fdate=dofc(return_filing_date)
g					trait=0
qui				sum fdate if year==2011,d
replace			trait=1 if year==2011 & fdate<=r(p50)
qui				sum fdate if year==2010,d
replace			trait=1 if year==2010 & fdate<=r(p50)
local				j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			se=e(V)
matrix			table[`i',`j']=[trait]1
matrix			table[`i'+1,`j']=sqrt(se[2,2])
local				j=`j'+1
matrix			table[`i',`j']=[trait]0
matrix			table[`i'+1,`j']=sqrt(se[1,1])
local				j=`j'+1
}
local				i=`i'+2
restore

/* AGE */

preserve
drop				if birth_foundation_date==.
g 					double bdate=dofc(birth_foundation_date)
g 					byear=year(bdate)
g 					age=2016-byear								
qui				sum age,d
g					trait=(age<=r(p50))		
local				j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			se=e(V)
matrix			table[`i',`j']=[trait]1
matrix			table[`i'+1,`j']=sqrt(se[2,2])
local				j=`j'+1
matrix			table[`i',`j']=[trait]0
matrix			table[`i'+1,`j']=sqrt(se[1,1])
local				j=`j'+1
}
local				i=`i'+2
restore

/* BUNCHER */

g					buncher=0
replace			buncher=1 if taxableinc>290000 & taxableinc<=300000 & year==2010
replace			buncher=1 if taxableinc>340000 & taxableinc<=350000 & year==2011
replace			buncher=1 if taxableinc>490000 & taxableinc<=500000 
g					trait=buncher
local				j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			se=e(V)
matrix			table[`i',`j']=[trait]1
matrix			table[`i'+1,`j']=sqrt(se[2,2])
local				j=`j'+1
matrix			table[`i',`j']=[trait]0
matrix			table[`i'+1,`j']=sqrt(se[1,1])
local				j=`j'+1
}
local				i=`i'+2

/* STRICTLY DOMINATED CHOICE */

drop				trait
g					dominated=0
replace			dominated=1 if taxableinc>300000 & taxableinc<=324324 & year==2010
replace			dominated=1 if taxableinc>350000 & taxableinc<=378378 & year==2011
replace			dominated=1 if taxableinc>500000 & taxableinc<=555556 
g 					trait=dominated
local				j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			se=e(V)
matrix			table[`i',`j']=[trait]1
matrix			table[`i'+1,`j']=sqrt(se[2,2])
local				j=`j'+1
matrix			table[`i',`j']=[trait]0
matrix			table[`i'+1,`j']=sqrt(se[1,1])
local				j=`j'+1
}
local				i=`i'+2

/* REVISED RETURN */

drop				trait
drop				if section_code==""		
g					trait=section_code=="1205" 
local				j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			se=e(V)
matrix			table[`i',`j']=[trait]1
matrix			table[`i'+1,`j']=sqrt(se[2,2])
local				j=`j'+1
matrix			table[`i',`j']=[trait]0
matrix			table[`i'+1,`j']=sqrt(se[1,1])
local				j=`j'+1
}
local				i=`i'+2

/* EXPORTING THE TABLE */

svmat 			table
keep				tab*
keep				if _n<=33
g					c11=""
replace			c11="\qquad 25th percentile" in 1
replace			c11="\qquad Median" in 2
replace			c11="\qquad Mean" in 3
replace			c11="\qquad 75th percentile" in 4
replace			c11="\qquad 90th percentile" in 5
replace			c11="\qquad 25th percentile" in 6
replace			c11="\qquad Median" in 7
replace			c11="\qquad Mean" in 8
replace			c11="\qquad 75th percentile" in 9
replace			c11="\qquad 90th percentile" in 10
replace			c11="\qquad 25th percentile" in 11
replace			c11="\qquad Median" in 12
replace			c11="\qquad Mean" in 13
replace			c11="\qquad 75th percentile" in 14
replace			c11="\qquad 90th percentile" in 15
replace			c11="4. Top city" in 16
replace			c11="5. Business in other city" in 18
replace			c11="6. More than one businesses" in 20
replace			c11="7. Male" in 22
replace			c11="8. Early filer" in 24
replace			c11="9. Young" in 26
replace			c11="10. Buncher" in 28
replace			c11="11. Strictly dominated choice" in 30
replace			c11="12. Revised return" in 32

forvalues 		c=1/4 {
g					c`c'=string(table`c',"%9.3f")
}
forvalues		r=17(2)33 {
forvalues		c=1/4 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		s=1/6 {
g					s`s'="&"
}
g					l="\\"
replace			l="\\\\" in 5
replace			l="\\\\" in 10
replace			l="\\\\" in 15
order				c11 s1 c1 s2 c2 s3 s4 c3 s5 c4 l
browse			c11 s1 c1 s2 c2 s3 s4 c3 s5 c4 l




